#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<int>> &arr, int i, int j, int &sum){
    if(i < 0 || i >= arr.size() || j < 0 || j >= arr[0].size() || arr[i][j])
        return;
    if(i == 0 || i == arr.size() - 1 || j == 0 || j == arr[0].size()){
        sum = 0;
        return;
    }  
    arr[i][j] = 1;
    sum++;
    dfs(arr, i, j - 1, sum);
    dfs(arr, i - 1, j, sum);
    dfs(arr, i, j + 1, sum);
    dfs(arr, i + 1, j, sum);
}
int main(){
    vector<vector<int>> arr;
    int n;
    scanf("%d", &n);
    int num;
    for(int i = 0; i < n; i++){
        vector<int> temp;
        for(int j = 0; j < n; j++){
            scanf("%d", &num);
            temp.push_back(num);
        }
        arr.push_back(temp);
    }
    int res = 0;
    int sum = 0;
    for(int i = 0; i < n; i++){
        if(i == 0 || i == n - 1)
            continue;
        for(int j = 0; j < n; j++){
            if(j == 0 || j == n - 1)
                continue;
            if(arr[i][j] == 0){
                dfs(arr, i, j, sum);
                res += sum;
            }
        }
    }
    cout<<res<<endl;

    for(vector<vector<int>>::iterator it = arr.begin(); it != arr.end(); it++){
        vector<int> vs = *it;
        for(int i = 0; i < vs.size(); i++){
            cout<<vs[i]<<"\t";
        }
        cout<<endl;
    }
    return 0;
}